import unittest
import HtmlTestRunner
import tmpcases.testclass1 as t1
import tmpcases.testclass3 as t3
from tmpcases.testclass1 import TestClass1One
from tmpcases.testclass2 import TestClass2Two



def create_suite_a():
    st = unittest.TestSuite()
    loader = unittest.TestLoader()
    # 从模块中加载测试用例 (加载整个python文件中所有的用例)
    t1cases = loader.loadTestsFromModule(t1)
    t3cases = loader.loadTestsFromModule(t3)
    st.addTests(t1cases)
    st.addTests(t3cases)
    return st

def create_suite_b():
    st = unittest.TestSuite()
    loader = unittest.TestLoader()
    # 通过添加测试类的方法
    t1onecases = loader.loadTestsFromTestCase(TestClass1One)
    t2twocases = loader.loadTestsFromTestCase(TestClass2Two)
    st.addTests(t1onecases)
    st.addTests(t2twocases)
    return st

def create_suite_c():
    st = unittest.TestSuite()
    loader = unittest.TestLoader()
    t1 = loader.loadTestsFromNames(['tmpcases.testclass1','tmpcases.testclass2'])
    st.addTests(t1)
    return st

def create_suite_d():
    st = unittest.TestSuite()
    loader = unittest.TestLoader()
    t1 = loader.loadTestsFromName('tmpcases.testclass2.TestClass1Two')
    st.addTests(t1)
    return st

if __name__ == '__main__':
    # runner = unittest.TextTestRunner(verbosity=2,stream=open('./report.txt',mode='w' ,encoding='utf8'))
    # runner = HtmlTestRunner.HTMLTestRunner(report_title='apptest')
    import xmlrunner
    runner = xmlrunner.XMLTestRunner(output='reports')
    suite1 = create_suite_a()

    suite2 = create_suite_b()
    suite3 = create_suite_c()
    suite4 = create_suite_d()
    runner.run(suite4)